package com.aac.framwork.aacframwork.viewmodel;

import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;

import com.aac.framwork.aacframwork.entity.User;
import com.aac.framwork.aacframwork.repository.UserRepository;

import javax.inject.Inject;

public class UserProficleViewModel extends ViewModel {

    private UserRepository userRepo;

    private LiveData<User> user;

    @Inject // 使用Dagger2提供
    public UserProficleViewModel(UserRepository userRepo) {
        this.userRepo = userRepo;
    }

    public void init(Long userId) {
        if (this.user != null) {
            //ViewModel 在前一个fragment中被创建，所以user为改变
            return;
        }
        user = userRepo.getUser(userId);
    }

    public LiveData<User> getUser() {
        return user;
    }
}
